package com.up360.rapidcalc.aerolite.controller
{
    import com.up360.rapidcalc.aerolite.AeroliteCrisis;
    import com.up360.rapidcalc.aerolite.model.Aerolite;
    
    import flash.events.MouseEvent;

    /**
     * @author Tunie
     * @date   May 4, 2013
     */
    public class AeroliteCtrl extends BasicCtrl
    {
        public function AeroliteCtrl()
        {
            super();
        }
        
        override public function clear():void
        {
            // TODO Auto Generated method stub
            super.clear();
        }
        
        override public function control():void
        {
            super.control();
            var b_aerolite:Aerolite=_target as Aerolite;
            b_aerolite.addEventListener(MouseEvent.CLICK,aeroliteClick);
            b_aerolite.addEventListener(MouseEvent.ROLL_OVER,aeroRollOver);
            b_aerolite.addEventListener(MouseEvent.ROLL_OUT,aeroRollOut);
        }
        
        protected function aeroliteClick(event:MouseEvent):void
        {
			var b_item:Aerolite=_target as Aerolite;
            //判断玩家选择是否正确
            if(AeroliteCrisis.instance.judge(b_item))
            {
                AeroliteCrisis.instance.isPlayerClick=true;
                b_item.state=Aerolite.BLOWUP;
            }
        }
        
        protected function aeroRollOver(event:MouseEvent):void
        {
			var b_item:Aerolite=_target as Aerolite;
            if(b_item.state==Aerolite.BLOWUP) return;
			b_item.state=Aerolite.ACTIVE;
			b_item.parent.setChildIndex(b_item,b_item.parent.numChildren-1);
        }
        
        protected function aeroRollOut(event:MouseEvent):void
        {
			var b_item:Aerolite=_target as Aerolite;
            if(b_item.state==Aerolite.BLOWUP) return;
			b_item.state=Aerolite.NORMAL;
        }        
        
    }
}